<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<!--开发中$parent和$root一般都很少用，考虑到组件复用性-->
<div id="app">
    <cpn></cpn>
</div>

<template id="cpn">
    <div>
        <div>我是子组件</div>
        <ccpn></ccpn>
    </div>
</template>
<template id="ccpn">
    <div>
        <div>我是子组件的子组件</div>
        <button @click="btnClick">按钮</button>
    </div>
</template>
<script src="../../js/vue.js"></script>

<script>
    const vue = new Vue({
        el: "#app",
        data: {
            message: "Hello vue,你好！"
        },
        components:{
            cpn:{
                template: '#cpn',
                data(){
                    return {
                        name: '子组件zhangsan'
                    }
                },
                methods:{
                    showMessage(){
                        console.log("子组件的方法==showMessage")
                    }
                },
                components: {
                    ccpn:{
                        template: '#ccpn',
                        methods: {
                            btnClick(){
                                // 访问父组件
                                console.log("子子组件按钮。。。");
                                this.$parent.showMessage();
                                console.log(this.$parent.name);
                                // 访问根组件
                                console.log(this.$root.name);
                            }
                        }
                    }
                }
            }
        }
    });
</script>
</body>
</html>